//
//  MainViewAndNoReadViewController.m
//  lsOA
//
//  Created by 蓝水软件 on 16/8/16.
//  Copyright © 2016年 苏州蓝水有限公司. All rights reserved.
//

#import "MainViewAndNoReadViewController.h"
#import "DrawerViewController.h"
#import "InformationViewController.h"
#import "MyInformationViewController.h"
#import "OperationAnalysisViewController.h"
#import "MainCollectionViewCell.h"
#import "FeedBackViewController.h"
#import "ChangePassWordViewController.h"
#import "ShowPersonInforViewController.h"


@interface MainViewAndNoReadViewController (){
    UIButton *switchVCButton;
    NSInteger index;
    
}

@end

@implementation MainViewAndNoReadViewController
- (void)viewWillAppear:(BOOL)animated{
    self.RemoveGestureRecognizer(NO);
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.164 green:0.657 blue:0.915 alpha:1.000]];
//    [[UIApplication sharedApplication] setStatusBarHidden:TRUE];
    //注册观察者，监听通知发布
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushView:) name:@"pushViewController"object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
    self.RemoveGestureRecognizer(YES);
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"pushViewController" object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}

- (void)setUI{
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"主界面(背景)"]];
    UIButton* leftBtn= [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"菜单"] forState:UIControlStateNormal];
    leftBtn.frame = CGRectMake(0, 0, 25, 25);
    UIBarButtonItem* leftBtnItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    [leftBtn addTarget:self action:@selector(leftBarButtonItem) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem setLeftBarButtonItem:leftBtnItem];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.child1 = [[MainViewController alloc]init];
    [self addChildViewController:self.child1];
    [self.child1.view setFrame:CGRectMake(0, 0, KSWidth, KSHeight)];

    self.child2 = [[NoReadViewController alloc]init];
    [self addChildViewController:self.child2];
    [self.child2.view setFrame:CGRectMake(0, 0, KSWidth, KSHeight)];
    
    [self.view addSubview:self.child2.view];
    self.currentViewController = self.child2;
    
    //下方切换按钮
    index = 2;
    switchVCButton = [[UIButton alloc]init];
    [self.view addSubview:switchVCButton];
    switchVCButton.backgroundColor = [UIColor colorWithRed:0.000 green:0.502 blue:0.251 alpha:1.000];
    switchVCButton.layer.cornerRadius = 50;
    switchVCButton.titleLabel.font = FONT(15);
    [switchVCButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(50);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    [switchVCButton setTitle:@"功能菜单" forState:UIControlStateNormal];
    [switchVCButton setTitleEdgeInsets:UIEdgeInsetsMake(10, 10, 50, 10)];
    switchVCButton.titleLabel.font = FONT(18);
    [switchVCButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    //导航栏标题
    self.title = @"功能菜单";
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"拉萨公交集团协同办公";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.bounds = CGRectMake(0, 0, 120, 30);
    if (IS_IPHONE_5) {
        titleLabel.font = FONT(15);
    }else{
        titleLabel.font = FONT(20);
    }
    self.navigationItem.titleView = titleLabel;
}




- (void)switchAction:(UIButton *)sender{
    if (index == 1) {
        index = 2;

        [switchVCButton setTitle:@"功能菜单" forState:UIControlStateNormal];
    }
    else{
        index = 1;
        //主

        [switchVCButton setTitle:@"代办事项" forState:UIControlStateNormal];
    }
    [self setTabBarViewIndex:index];

    
}

//响应通知方法
- (void)pushView:(NSNotification *)sender{
    
    [self leftBarButtonItem];
    NSString *row = [sender object][@"PushTo"];
    if ([row isEqualToString:@"0"]) {
        ShowPersonInforViewController *person = [[ShowPersonInforViewController alloc]init];
        [self.navigationController pushViewController:person animated:NO];
    }else if ([row isEqualToString:@"1"]){
        //修改密码
        ChangePassWordViewController *changPass = [ChangePassWordViewController new];
        [self.navigationController pushViewController:changPass animated:NO];
       
    }else if ([row isEqualToString:@"2"]){
        //意见反馈
        FeedBackViewController *feedBack = [FeedBackViewController new];
        [self.navigationController pushViewController:feedBack animated:NO];
    }
    
}

- (void)setTabBarViewIndex:(NSInteger)index2{
    if ((self.currentViewController == self.child1 && index2 == 1) ||
        (self.currentViewController == self.child2 && index2 == 2) ) {
        return;
    }
    switch (index2) {
        case 1:
        {
            [self transitionFromViewController:self.currentViewController toViewController:self.child1 duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
            }  completion:^(BOOL finished) {
                self.currentViewController = self.child1;
            }];
        }
            break;
        case 2:
        {
            [self transitionFromViewController:self.currentViewController toViewController:self.child2 duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
            }  completion:^(BOOL finished) {
                self.currentViewController = self.child2;
            }];
        }
            break;
        default:{
        
        }
            break;
    }
    [self.view bringSubviewToFront:switchVCButton];
    [self.view sendSubviewToBack:self.currentViewController.view];
}

- (void)leftBarButtonItem{
    self.leftActionBlock();

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}



@end
